package com.ease.common.util;

import java.util.List;
import java.util.Map;

import com.ease.common.vo.Pagination;

/**
 * 
 * @author nathanleewei
 * 
 */
public abstract class OutputUtil extends Detect {

	public static void err(String object) {
		System.err.print(object);
	}

	public static void p(String object) {
		System.out.println(object);
	}

	public static void p(String prefix, String object) {
		System.out.println(prefix + ": " + object);
	}

	public static void p(String prefix, Object object) {
		System.out.println(prefix + ": " + JsonUtil.marshal(object));
	}

	public static void p(Object object) {
		if (null == object) {
			p("null");
		} else {
			p(String.valueOf(object.getClass()), object);
		}
	}

	public static void p(String prefix, Pagination<?> pagination) {
		if (null == pagination) {
			p(prefix, "pagination not found");
		} else {
			p(prefix + " pagination:{start:" + pagination.getStart() + ", size:" + pagination.getSize() + ", count:" + pagination.getCount() + "}");
			p(prefix, pagination.getItems());
		}
	}

	public static void p(Pagination<?> pagination) {
		p("", pagination);
	}

	public static void p(String[] objects) {
		p("", objects);
	}

	public static void p(String prefix, String[] objects) {
		if (null != objects) {
			for (int i = 0; i < objects.length; i++) {
				p(prefix + " i[" + i + "]", objects[i]);
			}
			// } else {
			// p(prefix, "objects not found");
		}
	}

	public static void p(List<?> objects) {
		p("", objects);
	}

	public static void p(String prefix, List<?> objects) {
		if (null != objects) {
			int size = objects.size();
			p(prefix + " size=" + size);
			for (int i = 0; i < size; i++) {
				p(prefix + " i[" + i + "]", objects.get(i));
			}
			// } else {
			// p(prefix, "objects not found");
		}
	}

	public static void p(Map<?, ?> map) {
		if (null != map) {
			int count = 0;
			for (Map.Entry<?, ?> entry : map.entrySet()) {
				p(entry.getKey() + ": " + entry.getValue());
				count++;
			}
			p("[count]: ", count);
		} else {
			p("null");
		}
	}
}
